package com.example.home_stretch;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.google.gson.Gson;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.http.GET;

public class Grzx extends AppCompatActivity {
    private TextView tv_xm;
    private TextView tv_xb;
    private TextView tv_sj;
    private TextView tv_sfz;
    private TextView tv_time;
    private List<Grzl_list> crzl_list = new ArrayList<>();
    private List<Grzx_list1>grzx_list1=new ArrayList<>();
    private TextView tv_cph;
    private TextView tv_ye;
    private TextView tv_cph1;
    private TextView tv_ye1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.grzx);
        initView();
        initData();
        initData1();
    }

    public interface BlogService {
        @GET("getmyinfo")
        Call<ResponseBody> getBlog();
    }
    public interface BlogService1{
        @GET("carlist")
        Call<ResponseBody>getBlog();
    }
    public void initData1(){
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://hh1.me:5001")
                .build();
        BlogService1 service1=retrofit.create(BlogService1.class);
        Call<ResponseBody>call2=service1.getBlog();
        call2.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                Gson gson=new Gson();
                try {
                    Grzx_list1 carlist=gson.fromJson(response.body().string(),Grzx_list1.class);
                    grzx_list1.add(carlist);
                    tv_cph.setText(grzx_list1.get(0).getData().get(0).getCarno());
                    tv_cph1.setText(grzx_list1.get(0).getData().get(1).getCarno());
                    tv_ye.setText("余额"+grzx_list1.get(0).getData().get(0).getAmount()+"");
                    tv_ye1.setText("余额"+grzx_list1.get(0).getData().get(1).getAmount()+"");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {

            }
        });
    }
    public void initData() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http:hh1.me:5001/")
                .build();
        BlogService service = retrofit.create(BlogService.class);
        Call<ResponseBody> call = service.getBlog();
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                Gson gson = new Gson();
                try {
                    String s = response.body().string();
                    Grzl_list carlist = gson.fromJson(s, Grzl_list.class);
                    crzl_list.add(carlist);
                    Log.i("TAG", "onResponse65468464" + s);
                    tv_xm.setText("用户名：" + crzl_list.get(0).get姓名());
                    tv_xb.setText("姓名：" + crzl_list.get(0).get姓名());
                    tv_xb.setText("性别：" + crzl_list.get(0).get性别());
                    tv_sj.setText("手机：" + crzl_list.get(0).get手机号码());
                    tv_sfz.setText("手机：" + crzl_list.get(0).get身份证号码());
                    tv_time.setText("注册时间：" + crzl_list.get(0).get注册时间());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Log.i("TAG", "onFailure: " + "31564654");
            }
        });
    }

    private void initView() {
        tv_xm = (TextView) findViewById(R.id.tv_xm);
        tv_xb = (TextView) findViewById(R.id.tv_xb);
        tv_sj = (TextView) findViewById(R.id.tv_sj);
        tv_sfz = (TextView) findViewById(R.id.tv_sfz);
        tv_time = (TextView) findViewById(R.id.tv_time);
        tv_cph = (TextView) findViewById(R.id.tv_cph);
        tv_ye = (TextView) findViewById(R.id.tv_ye);
        tv_cph1 = (TextView) findViewById(R.id.tv_cph1);
        tv_ye1 = (TextView) findViewById(R.id.tv_ye1);
    }
}
